package com.ldk.springboot2021.controller;

import com.ldk.springboot2021.pojo.Door;
import com.ldk.springboot2021.service.DoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

@Controller
@RequestMapping("/door")
public class DoorController {
    @Autowired(required = false)
    private DoorService doorService;
    //添加门店业务
    @PostMapping("/add")///add来自PageController
    //函数最合理的是返回String
    public String addDoor(@RequestParam("name") String doorname,
                          @RequestParam("tel") String telephone, Model model){//若形参和前端的不一样，使用注解说明
        String view = doorService.addDoorInfo(doorname, telephone, model);
        return view;
    }

    //查询所有门店信息
    @RequestMapping("/findAllDoors")
    public String findAllDoorsInfo(Model model){
        return  doorService.findAllDoorsInfo(model);
    }
    //删除指定门店信息
    @RequestMapping("/deleteByDoorId")
    public String deleteById(Integer id){
        return doorService.deleteByDoorId(id);
    }
    @RequestMapping("toUpdateByDoorId")
   public String toUpdateByDoorId(Integer id,Model model){
        return doorService.toUpdateByDoorId(id,model);//这里和前端的id要一致
    }

    @RequestMapping("/update")
    public String updateById(Door door){
        return doorService.updateById(door);
    }
}
